package system.data;

import java.util.ArrayList;
import system.data.DataTable;
import system.data.DataRow;

public class Main {
	public static void main(String[] args) {
		DataTable dTable = new DataTable();
		dTable.addColumn("id");
		dTable.addColumn("name");
		dTable.addColumn("is_student");
		dTable.addColumn("age");
		dTable.addColumn("desc");

		DataRow row1 = dTable.newRow();
		row1.put("id", 1);
		row1.put("name", "zhangsan");
		row1.put("is_student", 1);
		row1.put("age", 25);
		row1.put("desc", "");
		dTable.add(row1);

		DataRow row2 = dTable.newRow();
		row2.put("id", 2);
		row2.put("name", "lishi");
		row2.put("is_student", 1);
		row2.put("age", 28);
		row2.put("desc", "");
		dTable.add(row2);

		DataRow row3 = dTable.newRow();
		row3.put("id", 3);
		row3.put("name", "qianduo");
		row3.put("is_student", 1);
		row3.put("age", 31);
		row3.put("desc", "leader's son");
		dTable.add(row3);

		DataRow row4 = dTable.newRow();
		row4.put("id", 4);
		row4.put("name", "zhaoliu");
		row4.put("is_student", 1);
		row4.put("age", 22);
		row4.put("desc", "");
		dTable.add(row4);

		DataRow row5 = dTable.newRow();
		row5.put("id", 5);
		row5.put("name", "sunqi");
		row5.put("is_student", 0);
		row5.put("age", 27);
		row5.put("desc", "");
		dTable.add(row5);

		ArrayList<DataRow> drs = dTable
				.select("(is_student==1 and age <= 25) or (is_student==0 and age < 30) or desc like 'leader%'");
		for (DataRow dr : drs) {
			System.out.println(String.format("%s\t%s", dr.get("id"),
					dr.get("name")));
		}
	}
}